<?php
class AuthController extends Bib_Controller_Action {
	public function loginAction()
	{
		$form = new Form_Auth_Login();
		$this->view->form = $form;
		if ($this->_request->isPost() && $form->isValid($this->_getAllParams())) {
			$adapter = new Bib_AuthAdapter($form->getValue('login'), $form->getValue('password'));
			$result = Zend_Auth::getInstance()->authenticate($adapter);
				
			if($result->getCode() == Zend_Auth_Result::SUCCESS) {
				$this->view->infoBox();
				$this->view->message = "Zalogowano.";
				$this->view->redirect = array('controller' => 'index');
			} else {
				$this->view->infoBox();
				$this->view->message = 'Nie udało się zalogować. Spróbuj ponownie';
				$this->view->redirect = array('controller' => 'auth', 'action' => 'login');
			}
		}
	}
	
	public function logoutAction() {
		Zend_Auth::getInstance()->clearIdentity();
	}
	
	
}